function testBase() {
    baseLog("/////////////////////////////////////////////////////////////////");
    baseLog("test base!");
}

function _getCallerFile() {
    let originalFunc = Error.prepareStackTrace;

    let callerFile;
    try {
        let err = new Error();
        Error.prepareStackTrace = function(err, stack) { return stack; };
        let currentFile = err.stack.shift().getFileName();

        while (err.stack.length) {
            callerFile = err.stack.shift().getFileName();
            if (currentFile !== callerFile) {
                break;
            }
        }
    } catch (e) {};

    Error.prepareStackTrace = originalFunc;
    callerFile = callerFile.replace(/^.*[\\\/]/, '');   // get the file name from absolute path
    callerFile = callerFile.substring(0, callerFile.lastIndexOf('.'));      // remove file's extension
    
    return callerFile;
}

function baseLog() {
    let callerFile = '[' + _getCallerFile() + '] ';
    let callerMethod = '[' + arguments?.callee?.caller?.name + '] ';
    if (arguments && arguments.length > 1) {
        let first = arguments[0];
        let arr = Array.prototype.slice.call(arguments);
        let more = arr.slice(1);
        console.log.call(console, callerFile, callerMethod, first, more);
    } else if (arguments && arguments.length == 1) {
        console.log.call(console, callerFile, callerMethod, arguments[0]);
    }
}


///////////////////////////////////////////////////////////////////////////////////////
testBase();
